28 #ifndef _spoton_pacify_h_
29 #define _spoton_pacify_h_
40 size_t n = passphrase.length();
54 m_passphrase_length = 0;
56 for(
size_t i = 0; i < n; i++)
57 if((
static_cast<int> (passphrase.at(i)) & 0xc0) != 0x80)
58 m_passphrase_length += 1;
60 if(m_passphrase_length > 0)
61 m_passphrase =
new long int[m_passphrase_length];
71 for(
size_t i = 0, j = 0; i < n; j++)
73 int c =
static_cast<int> (passphrase.at(i++));
80 m_passphrase[j] =
static_cast<long int> (c);
82 else if((c & 0xc0) == 0xc0)
112 m_passphrase[j] =
static_cast<long int> (c);
133 c =
static_cast<int> (passphrase.at(i++));
135 if((c & 0xc0) != 0x80)
151 m_passphrase[j] <<= 6;
152 m_passphrase[j] |=
static_cast<long int> (c & 0x3f);
167 delete []m_passphrase;
170 double evaluate(
void)
const
172 if(!m_passphrase || m_passphrase_length == 0)
177 std::map<long int, int> used;
178 std::map<double, int> classes;
183 for(
int i = 1; i <= 10; i++)
186 for(
size_t i = 0; i < m_passphrase_length; i++)
189 long int c = m_passphrase ? m_passphrase[i] : 0;
193 if(used.end() == used.find(c))
198 rc += std::pow(r, 2);
205 else if(qFuzzyCompare(3.0, r))
210 if(classes.end() == classes.find(r - 1.0))
211 classes[r - 1.0] = 0;
213 classes[r - 1.0] += 1;
217 if(c > 127 || last > 127)
218 r = distance(
'\0',
'\0');
220 r = distance(
static_cast<char> (c),
static_cast<char> (last));
222 rc += std::pow(r, 0.5);
237 for(std::map<double, int>::iterator it = classes.begin();
238 it != classes.end(); i++, it++)
250 if(qFuzzyIsNull(a + b + c + d))
254 double r = std::pow(a, 2) + std::pow(b, 2) + std::pow(c, 3) +
257 rc += 30.0 *
static_cast<double> (m_passphrase_length) /
261 return std::floor(rc + 0.5);
265 long int *m_passphrase;
266 size_t m_passphrase_length;
268 double char_class(
const long int c)
const
270 if(
static_cast<long int> (
'0') <= c && c <=
static_cast<long int> (
'9'))
272 else if(
static_cast<long int> (
'a') <= c &&
273 c <=
static_cast<long int> (
'z'))
275 else if(
static_cast<long int> (
'A') <= c &&
276 c <=
static_cast<long int> (
'Z'))
278 else if(c < (1 << 7))
280 else if(c < (1 << 8))
282 else if(c < (1 << 10))
284 else if(c < (1 << 14))
286 else if(c < (1 << 16))
288 else if(c < (1 << 18))
290 else if(c < (1 << 22))
292 else if(c < (1 << 26))
298 double distance(
const char a,
const char b)
const
305 std::transform(_a_.begin(), _a_.end(), _a_.begin(), ::tolower);
306 std::transform(_b_.begin(), _b_.end(), _b_.begin(), ::tolower);
311 std::map<char, std::pair<double, double> > keys;
312 std::string L1(
"1234567890");
313 std::string L2(
"qwertyuiop");
314 std::string L3(
"asdfghjkl");
315 std::string L4(
"zxcvbnm");
316 std::string _a_b_(_a_ + _b_);
318 for(
size_t i = 0; i < L1.length(); i++)
319 keys[L1[i]] = std::pair<double, double> (
static_cast<double> (i), 0.0);
321 for(
size_t i = 0; i < L2.length(); i++)
322 keys[L2[i]] = std::pair<double, double> (
static_cast<double> (i) + 0.5,
325 for(
size_t i = 0; i < L3.length(); i++)
326 keys[L3[i]] = std::pair<double, double> (
static_cast<double> (i) + 0.75,
329 for(
size_t i = 0; i < L4.length(); i++)
330 keys[L4[i]] = std::pair<double, double> (
static_cast<double> (i) + 1.0,
333 for(
size_t i = 0; i < _a_b_.length(); i++)
334 if(keys.end() == keys.find(_a_b_[i]))
337 return std::pow(std::pow(keys[_a_.at(0)].first -
338 keys[_b_.at(0)].first, 2) +
339 std::pow(keys[_a_.at(0)].second -
340 keys[_b_.at(0)].second, 2), 0.5);